<style lang="less">
    @import "../../../styles/table.less";
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card title="活动审核">
                    <Row @keydown.enter.native="handleSearch">
                        <Form ref="searchForm" :model="searchForm" inline :label-width="70">
                            <Form-item label="活动名称" prop="activityName">
                                <Input type="text" v-model="searchForm.activityName" placeholder="请输入活动名称" clearable style="width: 200px"/>
                            </Form-item>
                            <Form-item style="margin-left:-35px;" class="br">
                                <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                                <Button @click="handleReset">重置</Button>
                                <a class="drop-down" @click="dropDown">{{dropDownContent}}
                                    <Icon :type="dropDownIcon"></Icon>
                                </a>
                            </Form-item>
                        </Form>
                    </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns"  size="small"  :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
                    </Row>
                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                </Card>
            </Col>
        </Row>
        <activityrecord-drawer ref="activityrecordDrawer"></activityrecord-drawer>
    </div>
</template>

<script>
    import circleLoading from "../../my-components/circle-loading.vue";
    import {activityrecordList} from "@/api/bus";
    import activityrecordDrawer from "./activity-drawer";
    export default {
        name: "activity-manage",
        components: {
            activityrecordDrawer,
            circleLoading
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                drop: false,
                selectCount: 0, // 多选计数
                selectList: [], // 多选数据
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "a.activityType", // 默认排序字段
                    order: "desc", // 默认排序方式
                    courseTitle: "",
                    userName: "",
                    startDate: "",
                    activityName: "",
                    endDate: ""
                },
                selectDate: null, //选择日期绑定modal
                columns: [

                    {
                        type: "index",
                        width: 50,
                        fixed: "left",
                        align: "center"
                    },
                    {
                        title: "活动名称",
                        align: "center",
                        width: 250,
                        fixed: "left",
                        tooltip: true,
                        key: "activityName"
                    },
                    {
                        title: "用户名称",
                        width: 150,
                        align: "center",
                        key: "userName"
                    },
                    {
                        title: "审核状态",
                        align: "center",
                        width: 110,
                        key: "activityType",
                        render: (h, params) => {
                            if (params.row.activityType === 1) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "green"
                                            }
                                        },
                                        "通过"
                                    )
                                ]);
                            } else if (params.row.activityType === 0) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "red"
                                            }
                                        },
                                        "拒绝"
                                    )
                                ]);
                            } else if (params.row.activityType === 2) {
                                return h("div", [
                                    h(
                                        "Tag",
                                        {
                                            props: {
                                                color: "blue"
                                            }
                                        },
                                        "待审核"
                                    )
                                ]);
                            }
                        }
                    },
                    {
                        title: "增加学时",
                        align: "center",
                        width: 100,
                        key: "period"
                    },
                    {
                        title: "活动时间",
                        align: "center",
                        width: 250,
                        tooltip: true,
                        key: "activityTime"
                    },
                    {
                        title: "主办方",
                        align: "center",
                        width: 200,
                        tooltip: true,
                        key: "sponsor"
                    },
                    {
                        title: "证书",
                        align: "center",
                        width: 200,
                        tooltip: true,
                        key: "certificateName"
                    },
                    {
                        title: "创建时间",
                        align: "center",
                        width: 200,
                        key: "createTime"
                    },
                    {
                        title: "操作",
                        key: "action",
                        fixed: "right",
                        width: 150,
                        align: "center",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.edit(params.row);
                                            }
                                        }
                                    },
                                    "详情"
                                )
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            init() {
                this.getDataList();
            },
            getDataList() {
                this.loading = true;
                activityrecordList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                    }
                    console.info(this.data)
                });
            },
            edit(v) {
                let query = {id: v.id };
                this.$refs.activityrecordDrawer.showDrawer(query);
            },
            //设置课程推荐状态
            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getDataList();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                // 重新加载数据
                this.getDataList();
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
        },
        mounted() {
            this.init();
        }
    }
</script>
